package com.sptpc.student.controller;


import com.sptpc.student.model.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/stu")
public class StudentController {
    /**
     * 查询全部
     *
     */
    @GetMapping("/")
    public List<Student> getAll() {
        //后期从数据库查询
        List<Student> results = new ArrayList<>();
        results.add(Student.builder().id(1)
                .adminssionDate(LocalDate.parse("2019-09-01"))
                .name("张三")
                .major("移动应用开发")
                .build());
        results.add(Student.builder().id(2)
                .adminssionDate(LocalDate.parse("2019-09-01"))
                .name("李四")
                .major("移动应用开发")
                .build());
        results.add(Student.builder().id(3)
                .adminssionDate(LocalDate.parse("2019-09-01"))
                .name("王五")
                .major("软件技术")
                .build());
        return results;
    }

    /**
     * 新增
     *
     *
     */
    @PostMapping("/stu/add")
    public Student addNewStudent(@RequestBody Student student){
    log.info("新增学生：{}",student);
    Student student1=Student.builder().id(7)
            .name("邓思佳")
            .adminssionDate(LocalDate.parse("2019-09-01"))
            .major("移动应用开发")
            .build();
    return student1;
}

    /**
     * 删除
     *
     *
     */
    @DeleteMapping("/stu/del/{id}")
    public  String deleteDrink(@PathVariable Integer id){
        log.info("要删除的学生id：{}",id);
        return "删除操作成功";
    }

    /**
     * 查询指定
     */
    @GetMapping("/stu/{id}")
    public Student getStudent(@PathVariable("id") Integer id){
        log.info("要查询的学生id:{}",id);
        Student student2=Student.builder().id(3)
                .name("王五")
                .adminssionDate(LocalDate.parse("2019-09-01"))
                .major("软件技术")
                .build();
        return student2;
    }
    @PutMapping("/stu/update")
    public Student
}
